/**
 * struct ListNode {
 *	int val;
 *	struct ListNode *next;
 * };
 */

class Solution {
public:
    /**
     * 
     * @param head ListNode类 
     * @return ListNode类
     */
    ListNode* deleteDuplicates(ListNode* head) {
        // write code here
        ListNode*p=head;
        while(p)
        {
            auto q=p->next;
            //两两比较，如果相等
            while(q&&q->val==p->val)
            {
                auto r=q->next;
                p->next=r;
                free(q);
                q=r;
            }
            p=p->next;
        }
        return head;
    }
};